const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

module.exports =
{  module: {
    rules: [
      //JSX & JS
      {
        test: /\.jsx?$/,
        use: ['babel-loader']
      },
      // CSS
      {
        test: /\.css$/, 
        use: ["style-loader", "css-loader"]
      },
      // font
      {
        test: /\.(eot|woff(2)?)(\?[a-z0-9=&.]+)?$/,
        use: [
          {
            loader: 'file-loader',
            options: {outputPath: "font/"}  
          }
        ]
      }
    ]
  },
	entry: {
		main: "./src/app/main.js"
	},
	output:{
		path : path.resolve(__dirname, "./dist"),//需要绝对路径
		filename : "[name].js",
	},
	plugins: [
		new HtmlWebpackPlugin({
	      title: 'NW-Demo',
	      filename: 'index.html',
        inject: 'body',
	      template: "src/view/index.html",
        chunks: ['main']
      }),
    new CopyWebpackPlugin([
      //导入icon
      {
        from: path.resolve(__dirname, './src/assets/icon.png'),
        to: 'assets/icon.png'
      },
      //导入package.json
      {
        from: path.resolve(__dirname, './package.json'),
        to: 'package.json'
      }
      ])
	]
};